#include "UdpServer.hpp"
#include <iostream>
#include "IntAddr.hpp"
#include <memory>
#include"Route.hpp"
#include "ThreadPool.hpp"

using namespace MyThreadPool;

using task_t = std::function<void()>;

std::string defaulthandler(const std::string &msg)
{

    return "hello " + msg;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " port" << std::endl;
        return 1;
    }

    // std::string ip = argv[1];
    uint16_t port = std::stoi(argv[1]);

    Enable_Console_Log_Strategy();

    Route st;
    auto tp = ThreadPool<task_t>::GetInstance();

    // std::unique_ptr<UdpServer> Ser = std::make_unique<UdpServer>(port, [&st](int sockfd, const std::string &msg, InetAddr&peer)->void{
    //     st.MsgRoute(sockfd, msg, peer);
    // });
    std::unique_ptr<UdpServer> Ser = std::make_unique<UdpServer>(port, 
        [&tp ,&st](int sockfd,const std::string &msg,InetAddr &peer){
            task_t t = std::bind(&Route::MsgRoute, &st, sockfd, msg, peer);
            tp->Enqueue(t);
        }
    );

    Ser->Init();
    Ser->Start();

    return 0;
}